package com.sky.controller.rider;

import com.sky.dto.UserLoginDTO;
import com.sky.pojo.Courier;
import com.sky.result.Result;
import com.sky.service.common.OrderDispatchService;
import com.sky.service.rider.CourierService;
import com.sky.vo.CourierTradeOrderDetailVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/courier")
@Api(tags = "骑手相关接口")
public class CourierController {


    @Autowired
    private CourierService courierService;

    @Autowired
    private OrderDispatchService orderDispatchService;

    @PostMapping("/login")
    @ApiOperation("骑手登录")
    public Result<Courier> login(@RequestBody UserLoginDTO dto){

        return courierService.login(dto);
    }


    @GetMapping("/receivingOrder")
    @ApiOperation("骑手接单")
    public Result<String> receivingOrder(Long courierId,Long tradeNo){

        return courierService.receivingOrder(courierId,tradeNo);
    }


    @GetMapping("/transferOrderToTaskPool")
    @ApiOperation("骑手拒单")
    public Result<Courier> transferOrderToTaskPool(Long tradeNo,Long courierId){
        Courier courier = orderDispatchService.dispatch(null, tradeNo, courierId);
        return Result.success(courier);
    }

    @GetMapping("/findById")
    @ApiOperation("根据骑手的id查询骑手的信息")
    public Result<Courier> findById(Long id){

        return courierService.findById(id);
    }

    @GetMapping("/findCourierMonthTradeOrderInfo")
    @ApiOperation("骑手的月度统计")
    public Result<CourierTradeOrderDetailVO> findCourierMonthTradeOrderInfo(Long courierId,String date){

        return courierService.findCourierMonthTradeOrderInfo(courierId,date);

    }
}
